var t = a(require("@vant/weapp/dialog/dialog")), e = a(require("@vant/weapp/toast/toast"));

function a(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var o = require("../../utils/config"), n = require("../../utils/request"), i = require("../../utils/api"), r = (require("../../utils/date"), 
require("../../utils/storage")), s = require("../../utils/byte");

Page({
    data: {
        themeColor: getApp().globalData.themeColor,
        loadingHidden: !0,
        loadinginfo: "报告加载中...",
        icon: o.resourceRoot + "icon-report.png",
        phoneHeight: getApp().globalData.systemHeight,
        phoneWidth: getApp().globalData.systemWidth,
        pageIndex: 1,
        pageSize: 10,
        totalSize: 0,
        reportList: [],
        showDivder: !1,
        x: getApp().globalData.systemWidth - 120,
        y: getApp().globalData.systemHeight - 270,
        scale: 2,
        imagePath: o.resourceRoot,
        reportBanner: o.resourceRoot + "report-banner.png",
        reportCardImg: "url(" + o.resourceRoot + "report-item.png) no-repeat"
    },
    onShow: function() {
        this.setData({
            pageIndex: 1,
            pageSize: 10,
            totalSize: 0,
            reportList: [],
            showDivder: !1
        }), this.selectReportByPage();
    },
    onClose: function(a) {
        var o = this, r = a.detail, s = r.position, d = r.instance;
        switch (s) {
          case "left":
          case "cell":
            d.close();
            break;

          case "right":
            t.default.confirm({
                message: "确定删除吗？"
            }).then(function() {
                n.request(n.HttpMethod.GET, i.apiRoute.unBindCheckReportById + a.target.dataset.reportid, {}).then(function(t) {
                    "20000" == t.code ? ((0, e.default)({
                        message: "取消绑定成功",
                        duration: 5e3
                    }), o.setData({
                        pageIndex: 1,
                        pageSize: 10,
                        reportList: []
                    }), o.onShow()) : (0, e.default)({
                        message: t.message,
                        duration: 5e3
                    });
                });
            }).catch(function() {
                console.log("未删除");
            });
        }
    },
    searchReport: function() {
        wx.navigateTo({
            url: "/pages/my-link-report-search/my-link-report-search"
        });
    },
    onShareAppMessage: function() {
        return {
            title: "瑞慈体检预约 - 报告查询",
            path: "/pages/my-link-report/my-link-report"
        };
    },
    getReportDetail: function(t) {
        var e = t.target.dataset.reportid, a = t.target.dataset.showedsatisfactionquestion || !1;
        if (t.target.dataset.studyid.indexOf("-") > -1) {
            var r = this;
            this.setData({
                loadingHidden: !1,
                loadinginfo: "报告下载中..."
            }), n.request(n.HttpMethod.GET, i.apiRoute.desEncrypt + t.target.dataset.studyid, {}).then(function(i) {
                if ("20000" == i.code) {
                    var d = i.data, c = "".concat(o.reportUrl, "/PDFWechat?genStudyId=").concat(d, "&isA=true&source=WeChatApplet");
                    n.request(n.HttpMethod.GET, c, {}).then(function(o) {
                        if (null != o.Data) {
                            var n = wx.env.USER_DATA_PATH + "/" + t.target.dataset.name + "(" + t.target.dataset.studyid + ").pdf";
                            wx.downloadFile({
                                url: o.Data.Url,
                                filePath: n,
                                success: function(o) {
                                    r.setData({
                                        loadingHidden: !0,
                                        loadinginfo: "报告加载中..."
                                    }), 200 === o.statusCode && (r.setData({
                                        filePath: n,
                                        showPopup: !1
                                    }), wx.getFileInfo({
                                        filePath: n,
                                        success: function(o) {
                                            var i = s.changeByte(o.size);
                                            wx.navigateTo({
                                                url: "/pages/reportInfo-share/reportInfo-share?filePath=".concat(n, "&stid=").concat(t.target.dataset.studyid, "&name=").concat(t.target.dataset.name, "&size=").concat(i, "&reportid=").concat(e, "&showedsatisfactionquestion=").concat(a)
                                            });
                                        }
                                    }));
                                },
                                fail: function(t) {
                                    console.log(t);
                                }
                            });
                        }
                    });
                }
            });
        } else n.request(n.HttpMethod.GET, i.apiRoute.desEncrypt + t.target.dataset.studyid, {}).then(function(o) {
            if ("20000" == o.code) {
                var r = o.data;
                n.request(n.HttpMethod.GET, i.apiRoute.desEncrypt + t.target.dataset.nvalue, {}).then(function(o) {
                    if ("20000" == o.code) {
                        var n = o.data;
                        console.log(t.target.dataset), wx.navigateTo({
                            url: "/pages/reportInfo/reportInfo?studyid=".concat(r, "&type=").concat(t.target.dataset.type, "&parameter1=").concat(t.target.dataset.parameter1, "&parameter2=").concat(t.target.dataset.parameter2, "&nvalue=").concat(n, "&name=").concat(t.target.dataset.name, "&stid=").concat(t.target.dataset.studyid, "&reportid=").concat(e, "&showedsatisfactionquestion=").concat(a)
                        });
                    }
                });
            }
        });
    },
    getReportOnline: function(t) {
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var e = r.getStorageSync(r.storageKey.uid), a = "id=" + e + "&name=" + t.target.dataset.name + "&studyId=" + t.target.dataset.studyid.split("-")[0], n = encodeURIComponent(a), i = o.reportInterpretationDetailUrl + n;
        e && t.target.dataset.name && t.target.dataset.studyid.split("-")[0] ? wx.navigateTo({
            url: "/pages/webview/webview?h5=".concat(encodeURIComponent(i)),
            success: function() {
                wx.hideLoading();
            }
        }) : (wx.showToast({
            title: "体检信息不完整，暂不能进行报告解读",
            duration: 3e3,
            mask: !1,
            icon: "none"
        }), wx.hideLoading());
    },
    selectReportByPage: function() {
        var t = this;
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var e = "pageIndex=" + this.data.pageIndex + "&pageSize=" + this.data.pageSize;
        n.request(n.HttpMethod.GET, i.apiRoute.selectReportByPage + e, {}).then(function(e) {
            //lhd
            e = {
                "code":"20000",
                "data":{
                    records:[{
                        "medicalDate":"",
                        "typeCode":0,
                        "id":1,
                        "name":"cs",
                        "studyId":"cs-cs"
                    }]
                }
            }
            if ("20000" == e.code) {
                var a = [];
                e.data.records.forEach(function(t) {
                    t.medicalDate = t.medicalDate.split(" ")[0], null == t.type ? (t.typeCode = 0, t.typeName = "体检报告") : (t.typeCode = 1, 
                    t.typeName = "其他报告"), t.name.length > 3 ? t.nameStr = t.name.substring(0, 3) + "..." : t.nameStr = t.name, 
                    null == t.itemName ? (t.itemName = "", t.showItemName = !1) : (t.itemName.length > 8 ? t.itemName = t.itemName.substring(0, 12) + "..." : t.itemName = t.itemName, 
                    t.showItemName = !0);
                    var e = t.studyId.split("-")[0];
                    if (t.showStudyId = e, 12 == e.length) {
                        var o = parseInt(e.substring(0, 2));
                        a.push(o), t.insCode = o;
                    } else {
                        var n = parseInt(e.substring(0, 3));
                        a.push(n), t.insCode = n;
                    }
                }), n.request(n.HttpMethod.GET, i.apiRoute.selectWcaInstitutionByCodes + a.join(","), {}).then(function(a) {
                    if ("20000" == a.code) {
                        e.data.records.forEach(function(t) {
                            var e = a.data.filter(function(e) {
                                return e.code.toString() == t.insCode;
                            });
                            null != e && e.length > 0 ? null != e[0] && null != e[0].name && (t.insName = e[0].name) : t.insName = "";
                        });
                        var o = t.data.reportList.concat(e.data.records);
                        e.data.total <= t.data.pageSize && t.setData({
                            showDivder: !0
                        }), t.setData({
                            reportList: o,
                            totalSize: e.data.total
                        }), wx.hideLoading();
                    } else {
                        var n = t.data.reportList.concat(e.data.records);
                        e.data.total <= t.data.pageSize && t.setData({
                            showDivder: !0
                        }), t.setData({
                            reportList: n,
                            totalSize: e.data.total
                        }), wx.hideLoading();
                    }
                });
            } else wx.hideLoading();
        });
    },
    onScrollLower: function() {
        var t = this.data.pageIndex + 1;
        (t - 1) * this.data.pageSize > this.data.totalSize ? this.setData({
            showDivder: !0
        }) : (this.setData({
            pageIndex: t
        }), this.selectReportByPage());
    },
    reportInterpretation: function() {
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var t = r.getStorageSync(r.storageKey.uid), e = o.reportInterpretationUrl + t;
        wx.navigateTo({
            url: "/pages/webview/webview?h5=".concat(encodeURIComponent(e)),
            success: function() {
                wx.hideLoading();
            }
        });
    }
});